home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / RGASM.RAR / ASMCODE.EXE / CHAPT1-5 / DEMOSORT.ASM < prev    next >
Encoding:
Assembly Source File  |  1993-05-10  |  3.7 KB  |  84 lines

  1. ;***********************************************************************
  2. ;
  3. ;  Program DemoSort ( Chapter 4 )
  4. ;
  5. ;  Array sorting: demo program
  6. ;
  7. ;  Author:  A.I.Sopin, Voronezh University. 1993
  8. ;
  9. ;***********************************************************************
  10.         EXTRN   BSORT : FAR
  11.         .MODEL  SMALL
  12.         .STACK  100h
  13. ;----------------------------------------------------------
  14.         .DATA
  15. BELL    EQU     07      ;  sound signal
  16. LF      EQU     10      ;  Line Feed
  17. CR      EQU     13      ;  Carriage Return
  18. TEXT0   DB      CR, LF, CR, LF, " String sorting: demo program."
  19.         DB      "  Press any key to continue...", BELL, CR, LF, "$"
  20. TEXT1   DB      CR, LF, " Outputting an original sequence: "
  21.         DB      "  Press any key...", BELL, CR, LF, "$"
  22. TEXT2   DB      CR, LF
  23. ARRAY2  DB      "YYYYYYY EEEEEEE 1234567 ZZZZZZZ 0000000 QQQQQQQ "
  24.         DB      "$"
  25. TEXT3   DB      CR, LF, CR, LF,  " Increasing sequence. "
  26.         DB      "  Press any key...", BELL, CR, LF, "$"
  27. TEXT4   DB      CR, LF
  28. ARRAY4  DB      "YYYYYYY EEEEEEE 1234567 ZZZZZZZ 0000000 QQQQQQQ ", "$"
  29. TEXT5   DB      CR, LF, CR, LF,  " Decreasing sequence. "
  30.         DB      "  Press any key...", BELL, CR, LF, "$"
  31. ERTXT   DB      CR, LF, CR, LF,  " Sorting error.  "
  32.         DB      "  Press any key...", BELL, CR, LF, "$"
  33. VMODE   DB      0       ;  video mode saved
  34. ;----------------------------------------------------------
  35.         .CODE
  36. OutMsg  macro   Txt
  37.         lea     dx,Txt                  ;  addres of message
  38.         mov     ah,09h                  ;  function 09h - output text string
  39.         int     21h                     ;  DOS  service call
  40.         endm
  41.  
  42. WaitKey macro
  43.         mov     ah,0                    ;  function 0 - wait for key pressed
  44.         int     16h                     ;  BIOS keyboard service
  45.    endm
  46.  
  47. ;-------------------------------------------------------------------
  48. .STARTUP
  49. ;  Output initial message
  50.         OutMsg TEXT0                    ;  output initial message
  51.         WaitKey
  52. ;
  53.         OutMsg  TEXT1                   ;  output initial message
  54.         OutMsg  TEXT2                   ;  output initial message
  55.         WaitKey
  56. ;  Call subroutine BSORT - sorting array (increasing)
  57.         mov     ax,0                    ;  AX = 0 for increasing sequence
  58.         mov     cx,8                    ;  length of record
  59.         mov     dx,6                    ;  number of records
  60.         lea     si,ARRAY2               ;  DS:[SI] - address of array to be sorted
  61.         Call    BSORT                   ;  perform sorting
  62.         cmp     ax,0                    ;  normal return?
  63.         jnz     ErSort                  ;  if not, output error message and exit
  64.         OutMsg  TEXT3                   ;  output header
  65.         OutMsg  ARRAY2                  ;  output array sorted
  66.         WaitKey
  67. ;  Call subroutine BSORT - sorting array (decreasing)
  68.         mov       ax,1                    ;  AX = 1 for decreasing sequence
  69.         mov     cx,8                    ;  length of record
  70.         mov     dx,6                    ;  number of records
  71.         lea     si,ARRAY4               ;  DS:[SI] - address of array to be sorted
  72.         Call    BSORT                   ;  perform sorting
  73.         cmp     ax,0                    ;  normal return?
  74.         jnz     ErSort                  ;  if not, output error message and exit
  75.         OutMsg  TEXT5                   ;  output header
  76.         OutMsg  ARRAY4                  ;  output array sorted
  77.         WaitKey
  78. ;-------------------------------------------------------------------
  79. ;  Terminate program and exit to DOS
  80. ExProgr:.exit          0
  81. ErSort:      OutMsg    ERTXT
  82.    .exit     1
  83.         END
  84.